"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const koa_router_1 = __importDefault(require("koa-router"));
const configTool_1 = __importDefault(require("../com/configTool"));
const swaggerJSDoc = require('swagger-jsdoc');
const DocRoutes = new koa_router_1.default({ prefix: '/Doc' });
let swaggerSpec = null;
DocRoutes
    .all('/api', async (ctx) => {
    if (swaggerSpec === null) {
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        await configTool_1.default.init();
        const baseConfig = configTool_1.default.baseConfig;
        const swaggerDefinition = {
            openapi: '3.0.0',
            info: {
                title: '无人飞行器数据服务平台',
                version: configTool_1.default.baseConfig.version_time,
                description: '无人飞行器数据服务平台 接口文档'
            },
            host: `${baseConfig.localIPAddress}:${baseConfig.proxyAfterProxy_Port}`,
            basePath: '/'
        };
        const options = {
            failOnErrors: true,
            swaggerDefinition,
            apis: [
                './plug/routes/*.js',
                './src/routes/*.js'
            ]
        };
        swaggerSpec = swaggerJSDoc(options);
    }
    ctx.body = swaggerSpec;
});
exports.default = DocRoutes;
